package com.copm.ifm.servers.sys.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.copm.ifm.base.api.pojo.PageDTO;
import com.copm.ifm.base.api.pojo.PageVO;
import com.copm.ifm.base.basic.constant.DbConstants;
import com.copm.ifm.base.basic.util.AuthUtil;
import com.copm.ifm.base.service.mp.page.PageProxy;
import com.copm.ifm.servers.sys.dto.SysEcTypeDTO;
import com.copm.ifm.servers.sys.entity.SysEcType;
import com.copm.ifm.servers.sys.mapper.SysEcTypeMapper;
import com.copm.ifm.servers.sys.service.SysEcTypeService;
import com.copm.ifm.servers.sys.vo.SysEcTypeVO;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;

/**
 * 能耗类型表 服务实现类
 *
 * @author tp
 * @since 2021-01-05
 */
@Service
public class SysEcTypeServiceImpl extends ServiceImpl<SysEcTypeMapper, SysEcType> implements SysEcTypeService {

    @Resource
    SysEcTypeMapper sysEcTypeMapper;

    @Override
    public PageVO<SysEcTypeVO> selectForPage(PageDTO<SysEcTypeDTO> pageDTO) {
        return PageProxy.proxy(baseMapper::selectForPage, pageDTO);
    }

    @Override
    public SysEcType selectById(int id) {
        return baseMapper.selectById(id);
    }

    @Override
    public int countById(int id) {
        return sysEcTypeMapper.selectCount(
                new LambdaQueryWrapper<SysEcType>()
                        .eq(SysEcType::getId, id)
                        .eq(SysEcType::getDeleted, DbConstants.DEFAULT_NO)
        );
    }

    @Override
    public int updateDeleted(int id) {
        SysEcType sysEcType = new SysEcType();
        sysEcType.setId(id);
        sysEcType.setDeleted(DbConstants.DEFAULT_YES);
        return sysEcTypeMapper.updateById(sysEcType);
    }

    @Override
    public SysEcTypeVO selectVOById(int id) {
        return sysEcTypeMapper.selectVOById(id);
    }

    @Override
    public void updateEntityById(SysEcType entity) {
        entity.setUpdateBy(AuthUtil.getCurrentUserId());
        entity.setUpdateTime(new Date());
        updateById(entity);
    }
}
